package com.itxh.core.handler.statement;

import com.itxh.core.config.BoundSql;
import com.itxh.core.config.MappedStatement;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.List;

public class SimpleStatementHandler implements StatementHandler {
    private ResultSetHandler resultSetHandler ;

    public SimpleStatementHandler() {
        resultSetHandler = new DefaultResultSetHandler();
    }

    @Override
    public Statement prepare(Connection connection, String sql) throws Exception {
        return connection.createStatement();
    }

    @Override
    public void parameterize(Statement statement, Object param, BoundSql boundSql)  throws Exception{

    }

    @Override
    public <T> List<T> query(Statement statement, BoundSql boundSql, MappedStatement mappedStatement) throws Exception {
        ResultSet rs = statement.executeQuery(boundSql.getSql());
        return resultSetHandler.handleResultSet(rs,mappedStatement);
    }
}
